package org.pushforward.iwillsurvive.helpers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Error401Handler - Not Authorised
 */
@WebServlet(description = "Constructs the 401 Error", urlPatterns = { "/401" })
public class Error401Handler extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Error401Handler() 
    {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, 
						 HttpServletResponse response) 
						 throws ServletException, IOException 
	{
		String message = request.getParameter("ErrorMessage");

		String standard401Message = "You have attempted to access an area for which you are not authorised.<br><br>\n"
				+ "If you are not a registered user, you might want to consider registering.<br><br>\n" +
				"If you are, you might have not logged on correctly or your session expired.<br><br>\n" +
				"In any case, you might want to click " + PageBuilder.indexHereLink + ".<br>\n";
		
		PageBuilder.GenerateErrorPage(response, "iWillSurvive 401 Error Page",
									  "Error 401 - Not Authorised", standard401Message, message, 401);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doGet(request, response);
	}

}
